package com.gltqe.cipher;

import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;


/**
 * java对象反序列化修改器
 *
 * @author gltqe
 * @date 2023/6/14 15:00
 **/
public class CipherBeanDeserializerModifier extends BeanDeserializerModifier {

    private CipherDeserializer cipherDeserializer;

    public CipherBeanDeserializerModifier(CipherDeserializer cipherDeserializer) {
        this.cipherDeserializer = cipherDeserializer;
    }

    /**
     * 修改反序列化器
     *
     * @param config       反序列化配置,例如日期格式、属性命名策略
     * @param beanDesc     Java对象的描述,例如类名、字段信息
     * @param deserializer 反序列化器
     * @return: com.fasterxml.jackson.databind.JsonDeserializer<?>
     * @author gltqe
     * @date 2023/6/16 14:57
     **/
    @Override
    public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
        // 设置请求参数类型
        Class<?> beanClass = beanDesc.getBeanClass();
        cipherDeserializer.setBeanClass(beanClass);
        return cipherDeserializer;
    }
}
